package com.witmore.neutron.ai.web.wechat.controller;

import com.witmore.neutron.ai.web.wechat.dto.CustomMenuDTO;
import com.witmore.neutron.ai.web.wechat.dto.CustomMenuResponse;
import com.witmore.neutron.ai.web.wechat.service.WechatService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 微信自定义菜单控制器
 * Author: 豆子高
 * Date: 2025/12/19
 */
@Slf4j
@RestController
@RequestMapping("/api/wechat/menu")
@Tag(name = "微信自定义菜单管理", description = "微信服务号自定义菜单的创建、删除、查询等操作")
public class WechatMenuController {

    @Autowired
    private WechatService wechatService;

    /**
     * 创建默认自定义菜单
     *
     * @return 创建结果
     */
    @PostMapping("/create-default")
    @Operation(summary = "创建默认自定义菜单", description = "创建包含AI服务、关于我们等的默认自定义菜单")
    public CustomMenuResponse createDefaultMenu() {
        log.info("开始创建默认自定义菜单");
        CustomMenuResponse response = wechatService.createDefaultCustomMenu();
        log.info("创建默认自定义菜单完成，结果: {}", response);
        return response;
    }

    /**
     * 创建自定义菜单
     *
     * @param menuDTO 菜单配置
     * @return 创建结果
     */
    @PostMapping("/create")
    @Operation(summary = "创建自定义菜单", description = "根据提供的配置创建自定义菜单")
    public CustomMenuResponse createMenu(@RequestBody CustomMenuDTO menuDTO) {
        log.info("开始创建自定义菜单: {}", menuDTO);
        CustomMenuResponse response = wechatService.createCustomMenu(menuDTO);
        log.info("创建自定义菜单完成，结果: {}", response);
        return response;
    }

    /**
     * 删除自定义菜单
     *
     * @return 删除结果
     */
    @DeleteMapping("/delete")
    @Operation(summary = "删除自定义菜单", description = "删除当前的自定义菜单")
    public CustomMenuResponse deleteMenu() {
        log.info("开始删除自定义菜单");
        CustomMenuResponse response = wechatService.deleteCustomMenu();
        log.info("删除自定义菜单完成，结果: {}", response);
        return response;
    }

    /**
     * 获取自定义菜单配置
     *
     * @return 菜单配置
     */
    @GetMapping("/get")
    @Operation(summary = "获取自定义菜单配置", description = "获取当前的自定义菜单配置")
    public CustomMenuDTO getMenu() {
        log.info("开始获取自定义菜单配置");
        CustomMenuDTO menuDTO = wechatService.getCustomMenu();
        log.info("获取自定义菜单配置完成: {}", menuDTO);
        return menuDTO;
    }
}
